<?php
namespace home\Controller;
use Think\Controller;
use Home\Controller\CommonController;
class CatetoryController extends CommonController{
    public function index(){
    	$cid  = I('get.cid');
        $_SESSION =$cid;
    	$sql="select * from category where id ='{$cid}'";
    	$categoryinfo=M()->query($sql);
    	$this->assign('categoryinfo',$categoryinfo);


    	$count = M('question_category')->where("cid='{$cid}'")->count();
    	// var_dump($count);
    	$Page  = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show  = $Page->show();// 分页显示输出


    	 $sql="select t3.*,t4.username  from category as t1 inner join question_category as t2 on t1.id=t2.cid inner join question as t3 on t2.qid=t3.id inner join user t4 on t3.uid=t4.id where t1.id='{$cid}' order by t3.create_time desc limit $Page->firstRow,$Page->listRows";
    	 $list = M()->query($sql);

        foreach ($list as &$row) {
            $row['categorys'] = $this->getCategory($row['id']);
        }
      
    	$this->assign('list',$list);
        $this->assign('show',$show);
        $this->display();
    }

   
    public function getCategory($qid)
    {
        $sql = "select t2.id cid ,t2.cname from question_category t1 left join category t2 on t1.cid=t2.id where t1.qid='{$qid}'";
        return M()->query($sql);
    }

    
}

?>